import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @version 1.0
 * @Description:
 * @author: luobiao
 * @Date 2022/5/10 11:44
 */
public class Clean {

    public static void main(String[] args) {
        new Clean().test();
    }

    public void test(){
        LinkedHashMap<String, JSONObject> scoreMap=getMap("C:\\Users\\Administrator\\Desktop\\logs\\score.txt");
        LinkedHashMap<String, JSONObject> timeMap=getMap("C:\\Users\\Administrator\\Desktop\\logs\\time.txt");
        List<JSONObject> cleanList = new ArrayList<>();
        AtomicInteger count= new AtomicInteger();
        AtomicInteger index= new AtomicInteger();
        timeMap.forEach((k,v)->{
            index.getAndIncrement();
            if (!scoreMap.containsKey(k)) {
                count.getAndIncrement();
                System.out.println(v.getString("nickname")+"--->"+index.get());
                cleanList.add(v);
            }
        });
        System.out.println(count.get());
    }

    private LinkedHashMap<String, JSONObject> getMap(String fileUrl) {
        File file = new File(fileUrl);
        StringBuilder sb=new StringBuilder();
        FileUtil.readLines(file,"UTF-8").stream().forEach(f->sb.append(f));
        List<JSONObject> scoreList=JSONObject.parseArray(sb.toString(), JSONObject.class);
        LinkedHashMap<String, JSONObject> scoreMap = new LinkedHashMap<>();
        scoreList.stream().forEach(f->{
            String key=f.getString("user_id") ;
            if (scoreMap.containsKey(key)) {
                System.out.println(key);
            }
            scoreMap.put(key,f);
        });
        return scoreMap;
    }

}
